package org.byqh.dqeai.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.byqh.dqeai.common.Json;
import org.byqh.dqeai.dto.PkAppRuntimeDTO;
import org.byqh.dqeai.dto.common.IdListDto;
import org.byqh.dqeai.entity.PkAppRuntime;
import org.byqh.dqeai.entity.proxy.PkAppRuntimeProxy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/appr")
@Tag(name = "系统[PkAppRuntime] - 应用运行时管理")
public class PkAppRuntimeController extends BaseController<PkAppRuntime, PkAppRuntimeProxy> {
    /**
     * 查询全部运行时信息列表
     */
    @GetMapping(value = "/")
    public Json<List<PkAppRuntimeDTO>> list() {
        return this.listImpl(PkAppRuntimeDTO.class, query -> {
            return query.orderBy(r -> r.categoryId().asc())
                    .orderBy(p -> p.runtimeCode().asc());
        });
    }

    /**
     * 查询指定类别运行时信息列表
     */
    @GetMapping(value = "/{categoryId}")
    public Json<List<PkAppRuntimeDTO>> list(@PathVariable String categoryId) {
        return this.listImpl(PkAppRuntimeDTO.class, query -> {
            return query.where(r -> r.categoryId().eq(categoryId.trim()))
                    .orderBy(r -> r.categoryId().asc())
                    .orderBy(p -> p.runtimeCode().asc());
        });
    }

    /**
     * 按ID列表查询运行时信息列表
     */
    @PostMapping(value = "/listByIdList")
    public Json<List<PkAppRuntimeDTO>> listByIdList(
            @RequestBody IdListDto<String> dto) {
        return this.listImpl(PkAppRuntimeDTO.class, query -> {
            return query.where(r -> r.runtimeCode().in(dto.list))
                    .orderBy(r -> r.categoryId().asc())
                    .orderBy(p -> p.runtimeCode().asc());
        });
    }

    @Override
    @GetMapping(value = "/get/{id}")
    public Json<PkAppRuntime> get(String id) {
        return super.get(id);
    }
}